package com.shcowin.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.shcowin.dao.ContactDao;
import com.shcowin.entity.Contact;
import com.shcowin.mapper.ContactMapper;

@Repository
public class ContactDaoImpl implements ContactDao {

	@Inject
	private ContactMapper mapper;

	public boolean add(Contact entity) throws DataAccessException {
		boolean flag = false;
		try {
			mapper.add(entity);
			flag = true;
		} catch (DataAccessException e) {
			flag = false;
			throw e;
		}
		return flag;
	}

	public boolean edit(Contact entity) throws DataAccessException {
		boolean flag = false;
		try {
			mapper.edit(entity);
			flag = true;
		} catch (DataAccessException e) {
			flag = false;
			throw e;
		}
		return flag;
	}

	public Contact getById(Integer id) throws DataAccessException {
		Contact entity = null;
		try {
			entity = mapper.getById(id);
		} catch (DataAccessException e) {
			throw e;
		}
		return entity;
	}

	public List<Contact> getAll() throws DataAccessException {
		return mapper.getAll();
	}

	public void del(int id) throws DataAccessException {
		mapper.del(id);

	}

}